package com.design.movieticket.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.common.dto.XPage;
import com.design.movieticket.entity.Suggestion;
import com.design.movieticket.service.SuggestionService;
import com.design.movieticket.service.SuggestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Service
@Api(tags = "用户建议模块")
@RestController
@RequestMapping("/suggestion")
public class SuggestionController {
    @Resource
    private SuggestionService suggestionService;

    /** 分页查询 */
    @ApiOperation("用户建议信息分页展示")
    @GetMapping("/list/page")
    public Result findSuggestionInfoListByPage(Suggestion suggestion, XPage<Void> page) {
        IPage<Suggestion> suggestionInfoList = suggestionService.page(XPage.toIPage(page), suggestionService.buildQuery(suggestion));
        return new Result(suggestionInfoList, ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 新增或更新用户建议数据 */
    @ApiOperation("新增或更新用户建议数据")
    @PostMapping("/addOrUpdate")
    public Result addOrEditSuggestionInfo(Suggestion suggestion) {
        System.out.println(" suggestion"+suggestion);
        suggestionService.addOrUpdateSuggestionInfo(suggestion);
        return new Result(ResultStatus.SAVE_SUCCESS.getMsg(),ResultStatus.SAVE_SUCCESS.getCode());
    }

    /** 获取用户建议信息 */
    @ApiOperation("获取用户建议信息详情")
    @GetMapping("/getSuggestionDetail/{id}")
    public Result getSuggestionInfoDetail(@PathVariable long id){
        return new Result(suggestionService.getSuggestionDetail(id),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 删除用户建议信息 */
    @ApiOperation("删除用户建议信息")
    @PostMapping("/delSuggestionById/{id}")
    public Result delSuggestionInfoById(@PathVariable long id){
        suggestionService.delSuggestionById(id);
        return new Result(ResultStatus.DELETE_SUCCESS.getMsg(),ResultStatus.DELETE_SUCCESS.getCode());
    }
}
